﻿app.controller("base1Controller", function ($scope, base1Service, $window,
    encabezadoService, proveedorService, tabla10Service,
    baseImponibleService, elementoService) {


    encabezadoService.getList().then(function (results) {
        $scope.encabezadoList = results.data;
    }, function (error) {
        console.log(error.data.message);
    });
    tabla10Service.getList().then(function (results) {
        $scope.tabla10List = results.data;
    }, function (error) {
        console.log(error.data.message);
    });
    proveedorService.getList().then(function (results) {
        $scope.proveedorList = results.data;
    }, function (error) {
        console.log(error.data.message);
    });
    baseImponibleService.getList().then(function (results) {
        $scope.baseImponibleList = results.data;
    }, function (error) {
        console.log(error.data.message);
    });

    elementoService.getList().then(function (results) {
        $scope.elementoList = results.data;
    }, function (error) {
        console.log(error.data.message);
    });
    $scope.hola = function () {
        console.log($scope.Serie);
    }
    $scope.list = [];

    $scope.lis = function () {
        base1Service.getList().then(function (results) {
            $scope.list = results.data;
        }, function (error) {
            console.log(error.data.message);
        });
    }
    $scope.getById = function (base1) {
        $scope.base1 = base1;
        $scope.formVisibility = true;
        console.log($scope.formVisibility)
    };

    $scope.save = function () {
    /*    $scope.base1.encabezadoModel.Estado = "";
      if ($scope.base1.encabezadoModel.Estado = 1){*/
            if ($scope.base1.Id) {
                base1Service.update({ Id: "" }, $scope.base1).then(function (results) {
                    console.log(results.data);
                    $scope.lis();
                }, function (error) {
                    console.log(error.data.message);
                });
            } else {
                base1Service.create($scope.base1).then(function (results) {
                    console.log(results.data);
                    $scope.lis();
                }, function (error) {
                    console.log(error.data.message);
                });
            }
            $scope.formVisibility = false;
            console.log($scope.formVisibility)
      /*   }
   else{
        return alert ("Mes no habilitado... consulte con el administrador")

    } */
}

    $scope.delete = function (base1) {
        if ($window.confirm('Confirm delete')) {
            base1Service.delete({ Id: base1.Id }).then(function (results) {
                console.log(results.data);
                $scope.lis();
            }, function (error) {
                console.log(error.data.message);
            });
        }
    }
    $scope.lis();
    
    $scope.formVisibility = false;
    $scope.ShowForm = function () {
        $scope.formVisibility = true;
        console.log($scope.formVisibility)
    }
    $scope.cancel = function () {
        $scope.formVisibility = false;
        console.log($scope.formVisibility)
    }   
});
